package com.itheima.servletcontent;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "ServletResponse1", urlPatterns = "/servletResponse1")
public class ServletResponse01 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //response.setStatus(302);
        //response.setHeader("Location","index.jsp");
        //虚拟项目名字
        //response.setHeader("Location","/day31_war_exploded/index.jsp");
        //response.sendRedirect("index.jsp");
/*        response.sendRedirect("/day31_war_exploded/index.jsp");
        System.out.println("response.sendRedirect(\"/day31_war_exploded/index.jsp\")");
        response.setContentType("text/html;charset=UTF-8");
        response.getWriter().println("5秒以后页面跳转!");
        response.setHeader("Refresh", "5;url=index.jsp");*/
        // 获得请求方式:
        System.out.println("请求方式:" + request.getMethod());
        // 获得客户机的IP地址:
        System.out.println("客户机IP地址:" + request.getRemoteAddr());
        // 获得请求参数的字符串
        System.out.println("请求参数的字符串:" + request.getQueryString());
        // 获得请求路径的URL和URI
        System.out.println("请求路径的URL:" + request.getRequestURL());
        System.out.println("请求路径的URI:" + request.getRequestURI());
    }
}
